package com.geping.etl.common.security.pwd.impl;

import com.geping.etl.common.security.pwd.PwdPolicyConstant;
import com.geping.etl.common.security.pwd.PwdPolicyService;
import com.geping.etl.common.security.pwd.PwdPolicyServiceDispatcher;
import com.geping.etl.common.security.pwd.bo.PwdPolicyBo;
import org.springframework.stereotype.Service;

@Service
public class DefaultPwdPolicyServiceImpl extends PwdPolicyServiceDispatcher implements PwdPolicyService {


    /**
     * 初始化密码策略
     */
    private PwdPolicyBo pwdPolicyBo=new PwdPolicyBo("不少于8位,至少包含大小写英文字母和阿拉伯数字");

    /**
     * 密码规则
     */
    private static String pattern="(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])[a-zA-Z0-9\\W]{8,}";

    @Override
    public boolean validate(String pwd) {
       return pwd.matches(pattern);
    }

    @Override
    public String getType() {
        return PwdPolicyConstant.DEFAULT_POLICY;
    }

    @Override
    public PwdPolicyBo getPwdPolicy() {
        return pwdPolicyBo;
    }

    public static void main(String[] args) {
        DefaultPwdPolicyServiceImpl defaultPwdPolicyServiceImpl=new DefaultPwdPolicyServiceImpl();
        System.out.println(defaultPwdPolicyServiceImpl.validate("!@#$%^&*56565566Y"));
    }

}